class User < ActiveRecord::Base
	after_destroy :ensure_an_admin_remains

  attr_accessible :name, :password_digest

  validates :name, presence: true, uniqueness: true

  def authenticate(password_input)
  	password_digest == password_input
  end

private
  def ensure_an_admin_remains
  	if User.count.zero?
  		raise "Can't delete last user"
  	end
  end
end
